#include<bits/stdc++.h>
using namespace std;
int t;
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin >> t;
    for (int i = 1; i <= t; ++i)
    {
        int cnt = 0;
        int n, m, l, v;
        cin >> n >> m >> l >> v;
        int d[100005],vv[100005],a[100005],p[100005];
        for (int j = 1; j <= n; ++j)
        {
            scanf("%d%d%d", &d[j], &vv[j], &a[j]);
        }
        for (int j = 1; j <= m; ++j)
        {
            scanf("%d", &p[j]);
        }
        int flag = p[m];
        for (int j = 1; j <= n; ++j)
        {
            if (vv[j] > v && d[j] <= flag)
                cnt++;
        }
        if (cnt)
            printf("%d %d\n", cnt, m - 1);
        else
            printf("%d %d\n", cnt, m);
    }
    return 0;
}
